package br.com.simulado.application;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.international.StatusMessage.Severity;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;

import br.com.simulador.model.Config;
import br.com.simulador.session.ConfigList;

@Startup()
@Scope(ScopeType.APPLICATION)
@Name("configuracaoService")
public class ConfiguracaoService  {
	
	@Logger
	Log log;

	@Out(scope=ScopeType.APPLICATION)
	Map<String, String> configuracao;
	
	@In(create=true)
	ConfigList configList;
	
	
	@In
	StatusMessages statusMessages;
	
	@In
	EntityManager entityManager;
	
	@Create
	public void load(){
		log.debug("Inciando configuracao");
		configuracao = new HashMap<String, String>();
		
		for(Config c : configList.getResultList()){
			configuracao.put(c.getName(), c.getDescription());
		}
		
		statusMessages.add(Severity.INFO, "Configuração Recarregada");
		log.debug("Finalizando configuracao");
	}
	
	
	public void install(){
		
	}
	
	
}
